package shujia.day03;

public class ArrayDemo6 {
    public static void main(String[] args) {
        //数组遍历(依次输出数组中的每一个元素)
        int[] arr1 = {123, 4, 1, 3, 6, 1, 65, 5, 6, 212};
        for (int i = 0; i < 10; i++) {
            System.out.println(arr1[i]);
        }
        System.out.println("====================================");
        // 如果元素有很多的话，你还能数的过来吗
        int[] arr2 = {123, 4, 1, 3, 6, 1, 65, 5, 6, 212, 123, 4, 1, 3, 6, 1, 65, 5, 6, 212, 23, 4, 1, 3, 6, 1, 65, 5, 6, 212, 23, 4, 1, 3, 6, 1, 65, 5, 6, 212, 23, 4, 1, 3, 6, 1, 65, 5, 6, 212, 23, 4, 1, 3, 6, 1, 65, 5, 6, 212, 23, 4, 1, 3, 6, 1, 65, 5, 6, 21223, 4, 1, 3, 6, 1, 65, 5, 6, 21223, 4, 1, 3, 6, 1, 65, 5, 6, 212};
        //java中的数组提供了一个属性：length
        //可以通过该属性获取数组的元素个数（长度）
//        System.out.println(arr2.length);
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
        System.out.println("====================================");
        //数组遍历(依次输出数组中的每一个元素)
        int[] arr3 = {123, 4, 1, 3, 6};
        for (int i = 0; i < arr3.length; i++) {
            if(i==0){
                System.out.print("["+arr3[i]+",");
            }else if(i==arr3.length-1){
                System.out.println(arr3[i]+"]");
            }else {
                System.out.print(arr3[i]+",");
            }
        }
        System.out.println("====================================");
        int[] arr4 = {11,22,33,44,55};
        printIntArray(arr4);
        System.out.println("====================================");
        int[] arr5 = {100,200,300};
        printIntArray(arr5);

    }


   /*
        定义一个方法所需要考虑的东西：
        1、返回值类型
        2、参数类型和个数
    */
    public static void printIntArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            if(i==0){
                System.out.print("["+array[i]+",");
            }else if(i==array.length-1){
                System.out.println(array[i]+"]");
            }else {
                System.out.print(array[i]+",");
            }
        }
    }
}
